package net.zjitc.config;

import net.zjitc.interceptor.AuthInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

//静态资源加载不了
//视图解析器  product/list  /page/product/list.jsp
@Configuration
@ComponentScan("net.zjitc.controller")
//@EnableWebMvc //开启mvc WebMvcConfigurer
public class SpringMvcConfig extends WebMvcConfigurationSupport{
    /**
     * 视图解析:没有起作用
     * @param registry
     */
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/page/", ".jsp");
        registry.jsp("/page/", ".html");
    }

    /**
     * 添加拦截器
     * @param registry
     */

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AuthInterceptor()).addPathPatterns("/**").excludePathPatterns("/login","/logout");
    }

    /**
     * 静态资源处理
     */
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/js/**")
//                .addResourceLocations("/js/");
//        super
//
//    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

//    @Bean
//    public InternalResourceViewResolver getInternalResourceViewResolver() {
//        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
//        viewResolver.setPrefix("/page/");
//        viewResolver.setSuffix("*.html");
//        return viewResolver;
//    }
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/static/**")  // 设置访问路径前缀
            .addResourceLocations("/static/"); // 设置静态资源存放路径
}

}
